package com.ruoyi.pms.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pms.domain.PmsTaskLog;
import com.ruoyi.pms.service.IPmsTaskLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务历史记录Controller
 *
 * @author huikai
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/pms/tasklog")
public class PmsTaskLogController extends BaseController
{
    @Autowired
    private IPmsTaskLogService pmsTaskLogService;

    /**
     * 查询任务历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('pms:tasklog:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsTaskLog pmsTaskLog)
    {
        startPage();
        List<PmsTaskLog> list = pmsTaskLogService.selectPmsTaskLogList(pmsTaskLog);
        return getDataTable(list);
    }

    /**
     * 导出任务历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('pms:tasklog:export')")
    @Log(title = "任务历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsTaskLog pmsTaskLog)
    {
        List<PmsTaskLog> list = pmsTaskLogService.selectPmsTaskLogList(pmsTaskLog);
        ExcelUtil<PmsTaskLog> util = new ExcelUtil<PmsTaskLog>(PmsTaskLog.class);
        util.exportExcel(response, list, "任务历史记录数据");
    }

    /**
     * 获取任务历史记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('pms:tasklog:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return success(pmsTaskLogService.getInfoByLogId(logId));
    }

    /**
     * 新增任务历史记录
     */
    @PreAuthorize("@ss.hasPermi('pms:tasklog:add')")
    @Log(title = "任务历史记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsTaskLog pmsTaskLog)
    {
        return toAjax(pmsTaskLogService.add(pmsTaskLog));
    }

    /**
     * 修改任务历史记录
     */
    @PreAuthorize("@ss.hasPermi('pms:tasklog:edit')")
    @Log(title = "任务历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsTaskLog pmsTaskLog)
    {
        return toAjax(pmsTaskLogService.edit(pmsTaskLog));
    }

    /**
     * 删除任务历史记录
     */
    @PreAuthorize("@ss.hasPermi('pms:tasklog:remove')")
    @Log(title = "任务历史记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(pmsTaskLogService.removeByLogIds(logIds));
    }
}